<%--
  Created by IntelliJ IDEA.
  systemParam: huangyanqiu
  Date: 2017/9/15
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增团购配置</title>
</head>

<body>
<form id="edit_group_purchase_form" class="form-horizontal">
    <div class="form-group">
        <label for="group_purchase_title" class="col-sm-4 control-label">配置项名称:</label>
        <div class="col-sm-8">
            <input type="text" id="group_purchase_title" name="group_purchase_title" class="form-control"
                   value="${groupPurchaseParam.title}"
                   placeholder="请输入配置项名称"/>
        </div>
    </div>
    <div class="form-group">
        <label for="lower_limit" class="col-sm-4 control-label">人数下限（含）:</label>
        <div class="col-sm-8">
            <input type="text" id="lower_limit" name="lower_limit" class="form-control"
                   value="${groupPurchaseParam.lower_limit}"
                   placeholder="请输入人数"/>
        </div>
    </div>
    <div class="form-group">
        <label for="upper_limit" class="col-sm-4 control-label">人数上限（含）:</label>
        <div class="col-sm-8">
            <input type="text" id="upper_limit" name="upper_limit" class="form-control"
                   value="${groupPurchaseParam.upper_limit}"
                   placeholder="请输入人数"/>
        </div>
    </div>
    <div class="form-group">
        <label for="group_purchase_discount" class="col-sm-4 control-label">折扣比例:</label>
        <div class="col-sm-8">
            <input type="text" id="group_purchase_discount" name="group_purchase_discount" class="form-control"
                   value="${groupPurchaseParam.discount}"
                   placeholder="请输入折扣比例（保留两位），例如：0.8"/>
        </div>
    </div>
    <div class="form-group">
        <label for="comment" class="col-sm-4 control-label">活动备注:</label>
        <div class="col-sm-8">
            <input type="text" id="comment" name="comment" class="form-control" value="${groupPurchaseParam.comment}"
                   placeholder="请输入活动备注"/>
        </div>
    </div>
</form>
</body>

<script type="text/javascript">

    // 配置验证规则，并获取该对象。模块主页面打开弹出框时需要用到该对象去校验录入字段是否符合要求。
    var myValidator = $("#edit_group_purchase_form").validate({
        rules: {
            group_purchase_title: {
                required : true,
                maxlength : 127
            },
            lower_limit: {
                required: true,
                number: true,
                maxlength : 9
            },
            upper_limit: {
                required: true,
                number: true,
                maxlength : 9
            },
            group_purchase_discount: {
                required: true,
                number: true,
                max: 1,
                min: 0
            },
            comment: {
                maxlength : 127
            }
        }
    });

 /*   // 自定义校验：人数上限和人数下限的比较
    jQuery.validator.addMethod("CompareNumOfPeople", function() {
        var upper_limit = $("#upper_limit").val();
        var lower_limit = $("#lower_limit").val();
        return true;
    }, "XX");*/

    function groupPurchaseParaSave() {
        var result = false;
        $.emsAjax({
            url: "/ems/grouppurchase/save",
            data: {
                title: $('#group_purchase_title').val(),
                lower_limit: $('#lower_limit').val(),
                upper_limit: $('#upper_limit').val(),
                discount: $('#group_purchase_discount').val(),
                comment: $('#comment').val(),
                id: "${groupPurchaseParam.id}"
            },
            success: function (resp) {
                if (resp.status == "000") {
                    result = true;
                    $.alert(resp.message);
                    search("#group_purchase_table", getQueryParams());
                } else {
                    $.errorAlert(resp.message);
                    search("#group_purchase_table", getQueryParams());
                }
            }
        });
        return result;
    }

</script>

</html>